home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / KADFILE.ZIP / COMBEXES.TXT next >
Text File  |  1995-03-06  |  5KB  |  129 lines

  1.  
  2.                            Appending Files to EXEs.
  3.                            
  4.     After seeing several questions on appending files to EXEs, I decided to 
  5. write this text.  I did NOT originate this idea.  While this text describes 
  6. "a" way of implementing the technique it may not be the best way for your 
  7. needs.  I have simply attempted to supply you with a basic understanding of 
  8. the process.
  9.  
  10.  
  11.                                   WHY?
  12.     
  13.     A couple years ago, I purchased a copy of Ultima 7.  After installing it 
  14. I looked at the directory.  There were a lot of files and moving any one of  
  15. them out of the directory crashed the program.  When I got Unreal by Future 
  16. Crew all of my preconceived ideas went out the window.
  17.  
  18.       1.  You can't run a 2meg EXE, can you?!
  19.       2.  Where are the music and graphic files?!
  20.       3.  How'd they do that? (This includes the effects :)
  21.  
  22. The answer to #1 : "It runs; therefore, you must be able to do it. Idiot!"
  23. The answer to #2 : "All the music and graphic files are contained IN the EXE."
  24. Question #3 is a little harder to explain, I still don't know exactly what FC 
  25. did, but the technique I discuss in this file gives you similar results.
  26.  
  27.  
  28.  
  29.                             Appending a file
  30.  
  31.     Before you append a file to the end of your EXE, ask yourself how do 
  32. access it.  If your adding 10 files how do you know where they are?  This is 
  33. actually really simple once you think it through.  Create a directory 
  34. structure of your own and make it the very last file you append! Use your own 
  35. structure if you want but feel free to use mine.
  36.  
  37. Directory structure:
  38.  
  39.        repeat
  40.            name - string
  41.            filepos - long int, pointer to the first byte of the file
  42.            filesize - long int
  43.        for each file being attach
  44.  
  45.        long int - number of entries
  46.  
  47.  
  48.  
  49. Since this is similar to a WAD file, we'll call is a KAD file. 
  50. KAD = Kodiak Wad file, get it a KAD file. 
  51. Okay, so it wasn't that good, lets move on.
  52.  
  53. To build the KAD file all you have to do is tack one file after another INTO 
  54. a single file and add the directory to the end of it.
  55.  
  56.  
  57. see packer.c
  58.  
  59.        Open output file
  60.        repeat
  61.            save the output's file position in directory structure
  62.            save the input's file name, ignoring path,  in directory structure
  63.            save the input's file size in directory structure
  64.            open input file
  65.            copy input file to output file
  66.            close input file
  67.        until all files are appended
  68.        save directory info
  69.        close file
  70.  
  71. Simple, ehh?
  72.  
  73. Now that you have the KAD file what do you do with it?
  74.  
  75. To access the KAD your code should read the directory into a memory array. 
  76. Just read the last dword of the KAD multiply by 8 (2 dwords) add 4, and seek 
  77. from the end of the file back that many bytes and fill your directory array 
  78. from there.
  79.  
  80. Now if you want to load the first file from the KAD, get the file offset from 
  81. your directory array, seek to the file position and load. What could be 
  82. simpler?  How about using a pre-written function GETFILE. :)
  83.  
  84. While you are developing your program use the KAD file.  Once your code is 
  85. done your ready for the final step. Instead of reading from the KAD file, 
  86. change the input name your program is looking for, to itself. Then repack the 
  87. files to the end of your EXE.
  88.  
  89. see packer.c
  90.  
  91.        Open EXE file
  92.        seek the end of the EXE file
  93.        repeat
  94.            save the output's file position in directory structure
  95.            save the input's file type in directory structure
  96.            save the input's file size in directory structure
  97.            open input file
  98.            copy input file to output file
  99.            close input file
  100.        until all files are appended
  101.        save directory info
  102.        close file
  103.  
  104. That's it! YOUR DONE!
  105.  
  106.  
  107.     Keep in mind that this is NOT the only way to accomplish this.  I have 
  108. included a fully functional KAD system implemented for Watcom C.  It includes 
  109. LZARI decompression routine.  If this file has helped you, let me know.  Feel 
  110. free to use the code included, but if you do greet me. A postcard would be 
  111. nice too. :)
  112.  
  113.  
  114. NOTE: I have heard it said "you can't do this when using an EXE compression 
  115. loader like Pklite." I have one thing to say......BULL!   The trick is to 
  116. compress your EXE prior to appending the KAD to it.
  117.  
  118.  
  119.  
  120. Coded by Kodiak of The Apollo Project                                    
  121. AKA Charles Jones                                                        
  122.     1122 s 32nd St #2                                                    
  123.     Omaha, NE 68105                                                      
  124.     (402)-346-8974                                                       
  125.                                                                          
  126. Email: CAD@UnOmaha.edu                                                   
  127. IRC  : #Coders (lo *, Bri_acid: I still want to be on OPPER's list)                                                           
  128.  
  129.